﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class UIFieldRunMapBossInfo : MonoBehaviour
    {
        public UILabel labBossTimer;

        private float timer = 0f;

        private string str = "";

        void Awake()
        {
            str = TableTextBlo.GetText("field_boss_refrush");
        }

        public float Timer
        {
            set
            {
                this.timer = value;
                if (timer < 0f) timer = 0f;

                var hour = (int)(timer / (60f * 60f));
                var minute = (int)(timer / 60f) % 60;
                var second = (int)timer % 60;
                
                var _Str = GetStr(hour) + ":" + GetStr(minute) + ":" + GetStr(second);
                this.labBossTimer.text = string.Format(str, _Str);
            }
            get
            {
                return timer;
            }
        }


        void Update()
        {
            if (Timer > 0f)
            {
                Timer -= Time.deltaTime;
            }
            else
            {
                Timer = 0f;
                gameObject.SetActive(false);
            }
        }
        
        /// <summary>
        /// 重置时间
        /// </summary>
        /// <param name="SecTime">秒</param>
        public void ResetTimer(float SecTime)
        {
            this.timer = SecTime;
            if(this.timer>0f)
            {
                gameObject.SetActive(true);
            }
        }

        string  GetStr(int num)
        {
            if (num < 10) return "0" + num;
            else
                return num + "";
        }
    }
}